//
//  CompanyHomeHeaderView.m
//  Btpin
//
//  Created by Vic on 2019/4/21.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "CompanyHomeHeaderView.h"
#import "NewsCarouselView.h"

@interface CompanyHomeHeaderView () <NewsCarouselViewDelegate>
{
    UILabel *jobLbl;
}
@end

@implementation CompanyHomeHeaderView

- (instancetype)initWithFrame:(CGRect)frame Target:(id)target {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
        self.delegate = target;
    }
    return self;
}
- (void)initUI {
    PSCarouselView *carouselView = [[PSCarouselView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HomeBannerHeight) images:@[@"home_banner_bg", @"home_banner_bg2", @"home_banner_bg3"] space:0 bgImage:@"home_banner_bg"];
    [self addSubview:carouselView];
//    __weak typeof(self) weakSelf = self;
//    carouselView.tapImage = ^(BannerModel *model) {
    carouselView.tapImage = ^ {
        NSLog(@"轮播图Tap");
        if (self.delegate && [self.delegate respondsToSelector:@selector(companyHomeHeaderViewBannerCarouselTap:)]) {
            [self.delegate companyHomeHeaderViewBannerCarouselTap:nil];
        }
    };
    
    
    UIImageView *inviteImgView = [UIToolsControl initImageViewWithFrame:CGRectMake(20*Scale, EndY(carouselView), WIDTH-20*Scale, 125*Scale) imageName:@"home_invite_bg"];
    inviteImgView.userInteractionEnabled = YES;
    [self addSubview:inviteImgView];
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(inviteTapGesClick)];
    [inviteImgView addGestureRecognizer:tapGes];
    
    NewsCarouselView *newView = [[NewsCarouselView alloc] initWithFrame:CGRectMake(0, EndY(inviteImgView), WIDTH, 50*Scale) target:self];
    [self addSubview:newView];
    
    UIView *lineView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(newView), WIDTH, 8*Scale) backgroundColor:THEMECOLOR_OF_GRAY];
    [self addSubview:lineView];
    
    UIView *bottomView = [UIToolsControl initViewWithFrame:CGRectMake(0, EndY(lineView), WIDTH, 44*Scale) backgroundColor:COLOR_OF_WHITE];
    [self addSubview:bottomView];
    [bottomView borderColor:THEMECOLOR_OF_TEXT_cccccc borderWidth:lineH borderType:BorderSideTypeBottom];
    jobLbl = [UIToolsControl initLabelWithFrame:CGRectMake(LeftSpace, 0, 300*Scale, 44*Scale) text:nil textColor:THEMECOLOR_OF_TEXT_333333 font:Font_17];
    [bottomView addSubview:jobLbl];
    UILabel *rightLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, 0, WIDTH-30*Scale, 44*Scale) text:@"其他职位 " textColor:THEMECOLOR_OF_TEXT_666666 font:Font_15];
    rightLbl.textAlignment = NSTextAlignmentRight;
    rightLbl.backgroundColor = COLOR_OF_CLEAR;
    [bottomView addSubview:rightLbl];
    UIImageView *imgView = [UIToolsControl initImageViewWithFrame:CGRectMake(EndX(rightLbl)+5*Scale, 15*Scale, 7*Scale, 13*Scale) imageName:@"jiantou_right"];
    imgView.userInteractionEnabled = NO;
    [bottomView addSubview:imgView];
    
    UIButton *selectJobBtn = [UIToolsControl initButtonWithFrame:CGRectMake(0, EndY(lineView), WIDTH, 44*Scale) imageName:nil target:self action:@selector(selectJobBtnTap) title:nil titleColor:nil];
    [self addSubview:selectJobBtn];
}
- (void)reloadDataForJob:(NSString *)job {
    jobLbl.text = job;
}
- (void)selectJobBtnTap {
    if (self.delegate && [self.delegate respondsToSelector:@selector(companyHomeHeaderViewSelectJobTap)]) {
        [self.delegate companyHomeHeaderViewSelectJobTap];
    }
}
- (void)inviteTapGesClick {
    if (self.delegate && [self.delegate respondsToSelector:@selector(companyHomeHeaderViewNewInvitationTap)]) {
        [self.delegate companyHomeHeaderViewNewInvitationTap];
    }
}
- (void)newsCarouselViewTap:(ArticleItemModel *_Nullable)model {
    if (self.delegate && [self.delegate respondsToSelector:@selector(companyHomeHeaderViewNewCarouselTap:)]) {
        [self.delegate companyHomeHeaderViewNewCarouselTap:model];
    }
}

@end
